import request from '@/utils/request';

/**
 * 分页查询设置项
 */
export async function pageSettings(params) {
  const res = await request.get('/order/settings/page', { params });
  if (res.data.code === 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 查询设置项列表
 */
export async function listSettings(params) {
  const res = await request.get('/order/settings/listSel', {
    params
  });
  if (res.data.code === 0 && res.data.data) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 返回设置项select列表
 */
export async function listSettingsSel(params) {
  const res = await request.get('/order/settings', {
    params
  });
  if (res.data.code === 0 && res.data.data) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 根据id查询设置项
 */
export async function getSettings(id) {
  const res = await request.get('/order/settings/' + id);
  if (res.data.code === 0 && res.data.data) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 添加设置项
 */
export async function addSettings(data) {
  const res = await request.post('/order/settings', data);
  if (res.data.code === 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 修改设置项
 */
export async function updateSettings(data) {
  const res = await request.put('/order/settings', data);
  if (res.data.code === 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 删除设置项
 */
export async function removeSettings(id) {
  const res = await request.delete('/order/settings/' + id);
  if (res.data.code === 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}
